package com.yanqu.road.server.channelserver.cmd.union;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.logic.ChannelMessageHelper;
import com.yanqu.road.server.channelserver.manager.activity.ChannelActivityUnionMgr;
import com.yanqu.road.server.cmd.CrossChannelCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.*;

@Cmd(code = Protocol.N_CHANNEL_QUERY_UNION, desc = "")
public class ChannelQueryUnionCmd extends CrossChannelCommand {

    private UnionProto.CrossUnionQueryReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = UnionProto.CrossUnionQueryReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        int channelId = ChannelActivityUnionMgr.getChannelId(reqMsg.getServerId());
        UnionProto.CrossUnionQueryReqMsg.Builder crossMsg = reqMsg.toBuilder();
        crossMsg.setUnionChannelId(channelId);
        if(channelId == 0){
            UnionProto.UnionQueryRespMsg.Builder respMsg = UnionProto.UnionQueryRespMsg.newBuilder();
            respMsg.setRet(GameErrorCode.E_UNION_NO_FOUND);
            ChannelMessageHelper.sendGamePacket(ClientProtocol.U_CROSS_UNION_QUERY, respMsg, reqMsg.getReqChannelId(), reqMsg.getReqServerId(), packet.getPlayerId());
        }else{
            ChannelMessageHelper.sendGamePacket(Cross3Protocol.C3_CROSS_QUERY_UNION, crossMsg, channelId, reqMsg.getServerId(), packet.getPlayerId());
        }
    }

    @Override
    public void sendData() {

    }
}
